# 自动收集所有.cpp和.h文件（递归子目录）
file(GLOB_RECURSE SOURCES "*.cpp" "*.c")
file(GLOB_RECURSE HEADERS "*.h" "*.hpp")

message(STATUS "🍭agile_modbus_module 开始构建")

add_library(agile_modbus_module STATIC ${SOURCES})

target_include_directories(agile_modbus_module PUBLIC
  ${CMAKE_CURRENT_SOURCE_DIR}/inc
  ${CMAKE_CURRENT_SOURCE_DIR}/util
  ${CMAKE_CURRENT_SOURCE_DIR}/interface
  ${CMAKE_CURRENT_SOURCE_DIR}/ # 添加当前文件目录
  ${CMAKE_SOURCE_DIR}/config # 访问根目录生成的Config.h
)


# 查找libgoogle-glog库
find_library(GLOG_LIBRARY NAMES glog)
if(NOT GLOG_LIBRARY)
    message(FATAL_ERROR "glog library not found. Please install libgoogle-glog-dev package")
endif()

# 链接libgoogle-glog库
target_link_libraries(agile_modbus_module
    PRIVATE
    ${GLOG_LIBRARY}
)

# 显式链接线程库
target_link_libraries(agile_modbus_module PUBLIC Threads::Threads)
# 若需要进一步传递 -lrt 给依赖此库的可执行文件
target_link_options(agile_modbus_module PUBLIC -lrt)

